[GLOBAL _start_interrupts]
[GLOBAL _stop_interrupts]
[GLOBAL _halt_cpu]
[GLOBAL _isr_common]

[EXTERN _handle_interrupt]

_start_interrupts:
    sti
    ret

_stop_interrupts:
    cli
    ret

_halt_cpu:
    hlt
    ret

_isr_common:
    pusha

    mov ax, ds ;es, fs, gs, etc
    push eax

    mov ax, 0x10 ; Kernel data segment desc.
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax

    call _handle_interrupt

    pop eax
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax

    popa
	
    ; Pop interrupt arguments
    add esp, 8
	
    ; Re-enable interrupts, go back to where we were running before
    iret
